package com.ruoyi.client.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.supply.domain.SupplyInfo;
import com.ruoyi.supply.enums.SupplyInfoStatusEnum;
import com.ruoyi.supply.service.impl.SupplyInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 货源 资讯Controller
 * 
 * @author Ryan
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/client/info/supply")
@Api(tags = "客户端 货源 资讯")
public class ClientSupplyInfoController extends BaseController
{
    @Autowired
    private SupplyInfoService supplyInfoService;


    /**
     * 购买货源/地点的联系方式
     */
    @ApiOperation("获取货源联系方式")
    @GetMapping("/contact/{id}")
    public AjaxResult getContact(@PathVariable("id") Long id){
        String phone = supplyInfoService.clintGetContact(id);
        return AjaxResult.success("success",phone);
    }

    /**
     * 查询货源 资讯列表
     */
    @GetMapping("/list")
    @ApiOperation("查询货源 资讯")
    public TableDataInfo list(SupplyInfo supplyInfo)
    {
        startPage();
        supplyInfo.setStatus(SupplyInfoStatusEnum.AUDIT_PASS.getCode());
        List<SupplyInfo> list = supplyInfoService.selectInfoList(supplyInfo);
        if(CollUtil.isNotEmpty(list)){
            list.forEach(it->{
                it.setPhone(null);
            });
        }
        return getDataTable(list);
    }


    /**
     * 获取货源 资讯详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取货源 资讯详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        SupplyInfo supplyInfo = supplyInfoService.selectInfoById(id);
        supplyInfo.setPhone(null);
        return success(supplyInfo);
    }

    /**
     * 新增货源 资讯
     */
    @Log(title = "货源 资讯", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增货源 资讯")
    public AjaxResult add(@RequestBody SupplyInfo supplyInfo)
    {
        return toAjax(supplyInfoService.insertInfo(supplyInfo));
    }

    /**
     * 修改货源 资讯
     */
    @Log(title = "货源 资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改货源 资讯")
    public AjaxResult edit(@RequestBody SupplyInfo supplyInfo)
    {
        return toAjax(supplyInfoService.updateInfo(supplyInfo));
    }

    /**
     * 删除货源 资讯
     */
    @Log(title = "货源 资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation("删除货源 资讯")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(supplyInfoService.deleteInfoById(id));
    }



}
